import java.util.ArrayList;
import java.util.List;

public class Student {
    private String studentId;
    private String name;
    private String gender;
    private List<Course> selectedCourses = new ArrayList<>();

    public Student(String studentId, String name, String gender) {
        this.studentId = studentId;
        this.name = name;
        this.gender = gender;
    }

    public void selectCourse(Course course) {
        selectedCourses.add(course);
        System.out.println("学生" + name + "选修了课程" + course.getCourseName());
    }

    public void dropCourse(Course course) {
        if (selectedCourses.contains(course)) {
            selectedCourses.remove(course);
            System.out.println("学生" + name + "退选了课程" + course.getCourseName());
        } else {
            System.out.println("学生" + name + "未选修课程" + course.getCourseName() + "，无法退选");
        }
    }

    public void printTimetable(List<Teacher> teachers) {
        System.out.println("学生" + name + "的课表：");
        for (Course course : selectedCourses) {
            Teacher teacher = null;
            for (Teacher t : teachers) {
                if (t.getTeachingCourse() != null && t.getTeachingCourse().equals(course)) {
                    teacher = t;
                    break;
                }
            }
            String teacherName = teacher != null ? teacher.getName() : "未知";
            System.out.println("编号：" + course.getCourseId() + "，课程名称：" + course.getCourseName() + "，上课地点：" + course.getLocation() + "，时间：" + course.getTime() + "，授课教师：" + teacherName);
        }
    }
}